package gamer2;

import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
import javax.swing.JFrame;

import utils.Vec;



public class Renderer extends JFrame implements GLEventListener{

	private GLU m_glu = new GLU();
	public GL2 m_gl = null;
	private GLTools m_gltools = null;
	private Shader mShader = null;
	private Vec camera = new Vec(0,0,-1);
	private Vec target = new Vec(0,0,0);
	private Vec up = new Vec(0,1,0);
	
	public void display(GLAutoDrawable gLDrawable) {
		// triangle count


		m_gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
		m_gl.glLoadIdentity();
		
		mShader.Start();

		mShader.SetUniformParameter3f("camera", gamer2.rp.camera);
		mShader.SetUniformParameter3f("target", gamer2.rp.target);
		mShader.SetUniformParameter3f("up", gamer2.rp.up);
		
		m_gltools.RenderOrthoScreen();
		
		mShader.Stop();
		m_gl.glFlush();		
	}


	public void dispose(GLAutoDrawable arg0) {
		// TODO Auto-generated method stub
		
	}


	public void init(GLAutoDrawable glDrawable) {
		// TODO Auto-generated method stub
		m_gl =  glDrawable.getGL().getGL2();
		if (mShader==null) {
			try {
			mShader = new Shader(m_gl, "galaxy.vert", "galaxy.frag", "include");
			} catch (Exception se) {
				System.out.println(se.getMessage());
				System.exit(1);
			}
			
		}
		
		m_gltools = new GLTools(m_gl,
				512,
				512,
				camera, target,up);

		
	}


	public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3,
			int arg4) {
		// TODO Auto-generated method stub
		
	}

	
}
